package com.contract.spirit.ui.main.first.adapter

import com.contract.commonlib.util.ext.setOnSingleClickListener
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.contract.commonlib.util.CommonUtils
import com.contract.spirit.R
import com.contract.spirit.bean.entity.DialogBean
import com.contract.spirit.bean.response.MainPageResponse
import com.contract.spirit.databinding.AdapterExchangePollItemBinding
import com.contract.spirit.func.dialog.CommonRuleTipsDialog
import com.contract.spirit.func.dialog.base.BasePopDataBindImpl

/**
 * @author: witness
 * created: 2021/9/23
 * desc:
 */
class ExchangePollAdapter :
    BaseQuickAdapter<MainPageResponse.ExchangePollInfo, BaseDataBindingHolder<AdapterExchangePollItemBinding>>(
        R.layout.adapter_exchange_poll_item,
        ArrayList()
    ) {
    override fun convert(
        holder: BaseDataBindingHolder<AdapterExchangePollItemBinding>,
        item: MainPageResponse.ExchangePollInfo
    ) {
        val dataBinding = holder.dataBinding;
        dataBinding?.let {
            it.item = item
            it.ivRule.setOnSingleClickListener {
                showRuleDialog(item.maxPayRateTip)
            }
        }
    }

    private var ruleTipsDialog : CommonRuleTipsDialog? = null;
    private fun showRuleDialog(maxPayRateTip: String) {
        if (CommonUtils.isPopShow(ruleTipsDialog)) {
            return
        }
        val dialogBean = DialogBean()
        dialogBean.apply {
            isShowClose = true
            leftBtnText = ""
            rightBtnText = "我知道了"
            subTitle = maxPayRateTip
            title = "赔付说明"
            ruleTipsDialog = CommonRuleTipsDialog.show(context,this,object:
                BasePopDataBindImpl.OnDialogCallBack {
                override fun onRightBtnClick() {
                    super.onRightBtnClick()
                    ruleTipsDialog?.dismiss()
                }
            })
        }
    }
}